﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="frmBusquedaRecepcionDocumento.aspx.cs" Inherits="sistema_Despacho_frmBusquedaRecepcionDocumento" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <link href="../../kendoui.web/content/shared/styles/examples-offline.css" rel="stylesheet"/>
    <link href="../../kendoui.web/styles/kendo.common.min.css" rel="stylesheet"/>
    <link href="../../kendoui.web/styles/kendo.default.min.css" rel="stylesheet"/>
    <style type="text/css">
        #grdCotizaciones th.k-header { text-align: center }
    </style>

    <script src="../../kendoui.web/js/jquery.min.js" type="text/javascript"></script>
    <script src="../../kendoui.web/js/kendo.web.min.js" type="text/javascript"></script>
    <script src="../../kendoui.web/content/shared/js/console.js" type="text/javascript"></script>
</head>
<body>
    <div id="frmContainer" class="k-content">
    <table border="0" width="100%">
    <tr>
        <td colspan="8" align="center"><h2>Búsqueda de Documentos</h2></td>
    </tr>
    <tr>
        <td colspan="8" align="center">&nbsp;</td>
    </tr>
    <tr>
        <td>Número Recepción:</td>
        <td colspan="2"><input id="txtNroRecepcion" style="width: 250px" class="k-textbox" onkeypress="return onlyNumbers(event)" /></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="2"><button class="k-button" id="btnBuscar" style="width:160px;"><span class="k-icon k-i-search"></span>&nbsp;Buscar</button></td>
        <td>&nbsp;</td>        
    </tr>
    <tr>
        <td>Aseguradora:</td>
        <td colspan="2"><input id="cboAseguradora" style="width: 300px" /></td>
        <td>&nbsp;</td>
        <td>Tipo Documento:</td>
        <td colspan="2"><input id="cboDocumento" style="width: 300px" /></td>
    </tr>
    
    
    <tr>
        <td colspan="8" align="center">&nbsp;</td>
    </tr>
    <tr>
        <td colspan="8" align="center"><form name="form1" action=""><div id="grdRecepcionDocumento"></div></form></td>
    </tr>
    <tr>
        <td colspan="8" align="center">&nbsp;</td>
    </tr>
    <tr>
        <td colspan="8" align="center">
            <button class="k-button" id="btnRegistrar" style="width:160px;"><span class="k-icon k-i-plus"></span>&nbsp;Registrar</button>
            <button class="k-button" id="btnSalir" style="width:160px;"><span class="k-icon k-i-cancel"></span>&nbsp;Salir</button>
            
        </td>
    </tr>
    
    </table>

<script type="text/javascript">
        $(document).ready(function () {

            var cboAseguradora = $("#cboAseguradora").kendoComboBox({
                filter: "startswith",
                placeholder: "Seleccionar Aseguradora...",
                dataTextField: "dAseguradora",
                dataValueField: "cAseguradora",
                dataSource: {
                    transport: {
                        read: {
                            url: "http://localhost/Gra.Seguros.Servicio/RecepcionDocumento.svc/listarAseguradora",
                            data: {
                                Accept: "application/json"
                            }
                        }
                    }
                }
            }).data("kendoComboBox");


            var cboDocumento = $("#cboDocumento").kendoComboBox({
                filter: "startswith",
                placeholder: "Seleccionar Documento...",
                dataTextField: "dDocumento",
                dataValueField: "cDocumento",
                dataSource: {
                    transport: {
                        read: {
                            url: "http://localhost/Gra.Seguros.Servicio/RecepcionDocumento.svc/listarDocumento",
                            data: {
                                Accept: "application/json"
                            }
                        }
                    }
                }
            }).data("kendoComboBox");





            $("#btnBuscar").click(function () {
                var _txtNroRecepcion = "0";
                var _cboAseguradora = "0";
                var _cboDocumento = "0";


                if ($("#txtNroRecepcion").val() != "") _txtNroRecepcion = $("#txtNroRecepcion").val();
                if (cboAseguradora.value() != "") _cboAseguradora = cboAseguradora.value();
                if (cboDocumento.value() != "") _cboDocumento = cboDocumento.value();


//                alert(_txtNroRecepcion);
//                alert(_cboAseguradora);
//                alert(_cboDocumento);
                

                var grdRecepcionDocumentoData;

                grdRecepcionDocumentoData = new kendo.data.DataSource(
                {
                    transport: {
                        read: {
                            url: "http://localhost/Gra.Seguros.Servicio/RecepcionDocumento.svc/listarRecepcionDocumento/" + _txtNroRecepcion + "/" + _cboAseguradora + "/" + _cboDocumento,
                            data: {
                                Accept: "application/json"
                            }
                        }
                    },
                    pageSize: 10
                });

                $("#grdRecepcionDocumento").kendoGrid({
                    dataSource: grdRecepcionDocumentoData,
                    groupable: true,
                    sortable: true,
                    pageable: {
                        refresh: true,
                        pageSizes: true
                    },
                    selectable: "multiple",
                    dataBound: function () {
                        var grid = this;
                        grid.table.find("tr").find("td:first input")
                        .change(function (e) {
                            var checkbox = $(this);
                            var selected = grid.table.find("tr").find("td:first input:checked").closest("tr");
                            grid.clearSelection();
                            if (selected.length) {
                                grid.select(selected);
                            }
                        });
                    },
                    columns: [
                        { width: 16, headerTemplate: '<input id="checkAll" type="checkbox" onclick="ChequearTodos(this);" />', template: '<input id="${cRecepcionDocumento}" type="checkbox" />', filterable: false, sortable: false },
                        { width: 90, field: "cRecepcionDocumento", title: "Ticket" },
                        { width: 90, field: "dDocumento", title: "Tipo Documento" },
                        { width: 90, field: "fRecepcionDocumento", title: "Fecha de Recepcion" },

                    ]
                });
            });


            $("#btnRegistrar").click(function () {
                document.location.replace("frmRegistroRecepcionDocumento.aspx");
            });


            $("#btnSalir").click(function () {
                document.location.href = "../../Default.aspx";
            });               

        });

        

        


        











        /*Funciones de validación de campos*/

        function onlyNumbers(e) {
            var key = ASCIIKeyPressValue(e);

            var swFF = false;
            if (detectBrowser() == "FF") {
                if (key > 36 && key < 41 || key == 46) {
                    if (!e.shiftKey) swFF = true;
                }
            }

            if (swFF || key >= 48 && key <= 57) {

                return true;
            }
            return IsMovementOrEnterKey(key);
        }


        function ASCIIKeyPressValue(e) {
            var key;
            if (e.charCode != null && e.charCode != 0) {
                key = e.charCode;
            } else if (e.keyCode != null) {
                key = e.keyCode;
            } else if (e.which != null) {
                key = e.which;
            }
            return key;
        }


        function IsMovementOrEnterKey(key) {
            if (key <= 13) {
                return true;
            }
            return false;
        }


        function detectBrowser() {
            var mReturnValue = null
            var mAgent = new String(navigator.userAgent.toLowerCase())
            if (mAgent.indexOf("msie") !== -1) {
                mReturnValue = "IE"
            } else if (mAgent.indexOf("firefox") !== -1) {
                mReturnValue = "FF"
            } else if (mAgent.indexOf("chrome") !== -1) {
                mReturnValue = "CHR"
            } else if (mAgent.indexOf("safari") !== -1) {
                mReturnValue = "SF"
            } else if (mAgent.indexOf("opera") !== -1) {
                mReturnValue = "OP"
            }
            return mReturnValue
        }

        /*Funciones de validación de campos*/

        function ChequearTodos(chkbox) {
            for (var i = 0; i < document.forms["form1"].elements.length; i++) {
                var elemento = document.forms[0].elements[i];
                if (elemento.type == "checkbox") {
                    elemento.checked = chkbox.checked;
                }
            }

            if (chkbox.checked) {
                $('#grdRecepcionDocumento').data('kendoGrid').tbody.find("tr").addClass('k-state-selected');
            }
            else {
                $("#grdRecepcionDocumento").data("kendoGrid").clearSelection();
            }
        }


</script>

    </div>

</body>
</html>
